package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.converter.TestProductDetailConverter;
import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dal.persistence.ItemMapper;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.dto.TestProductDetailRequest;
import com.cskaoyan.shopping.dto.TestProductDetailResponse;
import com.cskaoyan.shopping.service.ITestProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @auther cskaoyan
 * @date 2022/6/16:17:46
 */
@Service
public class ITestProductDetailServiceImpl implements ITestProductDetailService {

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    TestProductDetailConverter productDetailConverter;

    @Override
    public TestProductDetailResponse testGetProductDetail(TestProductDetailRequest request) {
        TestProductDetailResponse testProductDetailResponse = new TestProductDetailResponse();
        try {
            // 参数校验
            request.requestCheck();
            Item item = itemMapper.selectByPrimaryKey(request.getProductId());
            TestProductDetailDto testProductDetailDto = productDetailConverter.ItemToProductDetailDto(item);

            // 成功执行
            testProductDetailResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            testProductDetailResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            testProductDetailResponse.setProductDetailDto(testProductDetailDto);
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionProcessorUtils.wrapperHandlerException(testProductDetailResponse, e);
        }
        return testProductDetailResponse;
    }
}
